package org.hawk.gwt.ppc.parser.impl;

import static org.hawk.gwt.ppc.parser.impl.DescriptorParserUtils.lookupNext;

import org.hawk.gwt.ppc.parser.Descriptor;
import org.hawk.gwt.ppc.parser.ExpressionDescriptor;
import org.hawk.gwt.ppc.parser.Token;
import org.hawk.gwt.ppc.utils.PreprocessorException;

/**
 * Parses line expression (terminated with ';').
 * 
 * @author alex.bereznevatiy@gmail.com
 *
 */
public class LineExpressionDescriptorParser implements DescriptorParser {

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.impl.DescriptorParser#accepts(org.hawk.gwt.ppc.parser.Token)
	 */
	public boolean accepts(Token token) {
		return true;
	}

	/*
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.parser.impl.DescriptorParser#parse(org.hawk.gwt.ppc.parser.impl.TokenBasedJavaParser, org.hawk.gwt.ppc.parser.impl.Tokenizer, java.lang.Object[])
	 */
	public Descriptor parse(TokenBasedJavaParser parser, Tokenizer tokenizer,
			Object... params) throws PreprocessorException {
		while (!tokenizer.current().equalsTo(';')) {
			lookupNext(tokenizer, false);
		}
		lookupNext(tokenizer, false);
		return new ExpressionDescriptorImpl();
	}

	private static class ExpressionDescriptorImpl extends AbstractDescriptor implements ExpressionDescriptor {
		
		public ExpressionDescriptor getParent() {
			return (ExpressionDescriptor) super.getParent();
		}
	}
}
